﻿// See https://aka.ms/new-console-template for more information
using System.Text;

using MD5_Trie_Demo;

Random random = new Random(Environment.TickCount);

#region 前缀树方案
//byte[] data = new byte[100];
//Span<byte> buffer = new Span<byte>(data);
//Trie trie = new Trie();

//for (int i = 0; i < 1000_000_000; i++)
//{
//    random.NextBytes(buffer);
//    string str = Encoding.UTF8.GetString(buffer);
//    string md5Hash = str.CalcMD5Hash();

//    if (trie.Search(md5Hash))
//    {
//        Console.WriteLine("数据已存在");
//        continue;
//    }

//    trie.Insert(md5Hash);
//    Console.WriteLine("新增数据");
//} 
#endregion

#region Hashset方案
byte[] data = new byte[100];
Span<byte> buffer = new Span<byte>(data);
HashSet<string> uniqueStrs = new HashSet<string>();

for (int i = 0; i < 1000_000_000; i++)
{
    random.NextBytes(buffer);
    string str = Encoding.UTF8.GetString(buffer);

    if (uniqueStrs.Add(str))
    {
        Console.WriteLine("新增数据");
        continue;
    }

    Console.WriteLine("数据已存在");
}
#endregion